package com.mall.goods.mapper;

import com.mall.goods.model.Sku;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 商品SKU表 Mapper 接口
 * </p>
 *
 * @author Darren
 * @since 2022-08-18
 */
@Mapper
public interface SkuMapper extends BaseMapper<Sku> {

    /**
     * 减少商品库存
     *
     * @param id
     * @param num
     * @return
     */
    @Update("UPDATE sku SET num = num - #{num} where id = #{id} and num >= #{num}")
    int reduceSkuNum(@Param("id") String id, @Param("num") Integer num);

}
